package com.oscarmovie.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.oscarmovie.Constants;
import com.oscarmovie.model.Category;
import com.oscarmovie.service.CategoryService;

public class CategoryAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	private CategoryService categoryService;
	
	private Category category;
	private List<Category> categories;

	
	public String add() throws Exception {
		setCategory(null);
		return Constants.ADD;
	}
	public String edit() throws Exception {
		loadAll();
		load();
		return Constants.EDIT;
	}
	public String save() throws Exception {
		categoryService.save(category);
		return edit();
	}

	public String load() throws Exception {
		this.category = categoryService.load(category.getId());
		return SUCCESS;
	}

	public String loadAll() throws Exception {
		this.categories = categoryService.loadAll();
		return SUCCESS;
	}


	public List<Category> getCategories() {
		return categories;
	}

	

	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

	public CategoryService getCategoryService() {
		return categoryService;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public Category getCategory() {
		return category;
	}

}
